<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../lib/vue-2.4.0.js"></script>
</head>

<body>
  <div id="app">
    <input type="text" v-model="user.firstName">
    <input type="text" v-model="user.lastName">
    <h2>{{user.fullName}}</h2>
  </div>
</body>
<script>
  let app = new Vue({
    el: '#app',
    data: {
      user: {
        firstName: '张',
        lastName: '狗子',
        fullName: ''
      }
    },
    watch: {
      'user.firstName': function (newVal, oldVal) {
        this.user.fullName = this.user.firstName + this.user.lastName
      }
    }
  })
</script>

</html>